<template>
  <div class="test">
    <canvas width="400" height="400" ref="cvsRef"></canvas>
  </div>
</template>

<script lang="ts">
import { defineComponent, onMounted, ref } from "vue";
import { mapNumToAngle } from "../utils/mapNumToAngle";
export default defineComponent({
  name: "test",
  setup() {
    const cvsRef = ref<HTMLCanvasElement>();
    onMounted(() => {
      const ctx = cvsRef.value?.getContext("2d");
      if (ctx) {
        ctx.fillStyle = "red";
        ctx.save();

        ctx.translate(100, 100);
        ctx.rotate((Math.PI / 180) * 45);
        ctx.fillStyle = "blue";
        ctx.fillRect(0, 0, 100, 100);

        ctx.restore();
        ctx.translate(0, 0);
        ctx.fillRect(0, 0, 50, 50);
      }
    });
    return { cvsRef };
  },
});
</script>
<style scoped>
.test {
  width: 100%;
  height: 100%;
  background-color: #eee;
}
canvas {
  border: 1px solid red;
}
</style>
